package com.example.xViewChat.Bean;

import io.ganguo.chat.core.protobuf.protoMsg;
import io.ganguo.chat.core.transport.Header;
import io.ganguo.chat.core.transport.IMRequest;
import io.ganguo.chat.core.transport.IMResponse;
import io.ganguo.chat.route.biz.entity.*;
import io.ganguo.chat.route.server.dto.*;

import java.util.HashMap;
import java.util.Iterator;

/**
 * Created by hasee on 2016-04-09.
 */
public class IntentBean extends BaseBean {
    public Header getHeader() {
        return header;
    }

    public void setHeader(Header header) {
        this.header = header;
    }

    public Object getEntity() {
        return entity;
    }

    public void setEntity(Object baseEntity) {
        this.entity = baseEntity;
    }

    Header header;
    Object entity;

    public IMResponse toResponse() {

        IMResponse response = new IMResponse();
        response.setHeader(header);
        if(entity == null){response.setData(null);}
        if (entity instanceof Login) response.writeEntity(new LoginDTO((Login) entity));
        if (entity instanceof Message) response.writeEntity(new MessageDTO((Message) entity));
        if (entity instanceof User) response.writeEntity(new UserDTO((User) entity));
        if (entity instanceof UserDetail) response.writeEntity(new UserDetailDTO((UserDetail) entity));


        return response;
    }
}
